
#include "root.h"

#include "ui_base_page.h"
#include "midea_collection_view.h"
#include "midea_collection_dynamic.h"
#include "../base_scroll_ui/midea_flex.h"
#include "../base_scroll_ui/midea_base_scroll_tool.h"
#include "../base_scroll_ui/midea_base_scroll_cell.h"

#include "msg_queue.h"
#include "img_queue.h"
#include "cmd_queue.h"
#include "pop_win.h"
#include "sys_scene.h"

#include "pt_dev.h"
#include "img_info.h"
#include "com_title.h"
#include "sys_font.h"
#include "pt_fs.h"

#include "startup_animation.h"

#include "root_page.h"

#include "home_page.h"
#include "scene_page.h"
#include "screen_protection.h"

#include "setting_download.h"
#include "setting_legal.h"
#include "setting_msg.h"
#include "setting_page.h"
#include "setting_page2.h"
#include "setting_policy.h"
#include "setting_reboot.h"
#include "setting_restore.h"
#include "setting_sys_update.h"
#include "setting_unbind.h"
#include "setting_up_err.h"
#include "setting_up_new.h"
#include "setting_update.h"

#include "dev_dwled.h"
#include "dev_swled.h"
#include "dev_mc.h"
#include "dev_oc.h"
#include "dev_jc.h"
#include "dev_purifier.h"
#include "dev_washer.h"

#include "msg_err.h"
#include "msg_mater.h"
/*******************************************************/
static root_ctl_t  root_ctl;
/*******************************************************/

int root_send_msg(int cmd,int d0,int d1,int d2,void* arg)
{
    msg_notify_t msg_send;

    msg_send.cmd   = cmd;
    msg_send.data0 = d0;
    msg_send.data1 = d1;
    msg_send.data2 = d2;
    msg_send.para  = arg;
    msg_queue_send(&msg_send);

    return 0;
}

static int root_ctl_page_init(void)
{
    root_ctl.len     = 0;
    root_ctl.e_head = (slist_t *)malloc(sizeof(slist_t));
	if(root_ctl.e_head == NULL){
		debug_e("e_head null\n");
		return -1;
	}
    slist_init(root_ctl.e_head);
    //***************************************************
    root_ctl.dev_head = (slist_t *)malloc(sizeof(slist_t));
	if(root_ctl.dev_head == NULL){
		debug_e("e_head null\n");
		return -1;
	}
    slist_init(root_ctl.dev_head);
    //***************************************************

    return 0;
}

static int root_device_add(char* name,char* id,char* type,char* subtype)
{
    device_link_t* device = NULL;

    if((!name)||(!id)||(!type)||(!subtype)){
        return -1;
    }
    if(!root_ctl.dev_head){
        return -1;
    }
    //****************************************************/
    device = (device_link_t *)malloc(sizeof(device_link_t));
    if(device == NULL){
        debug_e("device err\n");
        return -1;
    }
    memset(device, 0, sizeof(device_link_t));
    slist_init(&(device->e_tail));
    //****************************************************
    memset(device->e_attr.name,0,R_N_LEN);
    snprintf(device->e_attr.name,R_N_LEN,"%s",name);

    memset(device->e_attr.id,0,R_N_LEN);
    snprintf(device->e_attr.id,R_N_LEN,"%s",id);

    memset(device->e_attr.type,0,R_N_LEN);
    snprintf(device->e_attr.type,R_N_LEN,"%s",type);

    memset(device->e_attr.subtype,0,R_N_LEN);
    snprintf(device->e_attr.subtype,R_N_LEN,"%s",subtype);
    //****************************************************

    slist_add_tail(root_ctl.dev_head,&(device->e_tail));
    //****************************************************

    return 0;
}

static int root_device_del(void)
{
    int ret = 0;
    slist_t* node;
	device_link_t * obj = NULL;

    if(!root_ctl.dev_head){
        return -1;
    }

   	slist_for_each(node,(root_ctl.dev_head))
	{
		obj = slist_entry(node,device_link_t,e_tail);
		if(obj)
        {
            ret = 1;
            break;
		}
	}

    if(ret){
        slist_remove(root_ctl.dev_head, &(obj->e_tail));
        free(obj);
        obj = NULL;
    }

    return 0;
}

static int root_device_del_bydevid(char* devid)
{
    int ret = 0;
    slist_t* node;
	device_link_t * obj = NULL;

    if(!root_ctl.dev_head){
        return -1;
    }

   	slist_for_each(node,(root_ctl.dev_head))
	{
		obj = slist_entry(node,device_link_t,e_tail);
		if(obj)
        {
            if(!strcmp(obj->e_attr.id,devid))
            {
                ret = 1;
                break;
            }
		}
	}

    if(ret){
        slist_remove(root_ctl.dev_head, &(obj->e_tail));
        free(obj);
        obj = NULL;
    }

    return 0;
}


static int root_device_del_all(void)
{
    int i = 0;
    int device_num = 0;
    slist_t* node = NULL;
	device_link_t* obj = NULL;

    if(!root_ctl.dev_head){
        return -1;
    }

    device_num = root_device_get_num();
    debug_d("device_num=%d\n",device_num);
    for(i=0;i<device_num;i++)
    {
        root_device_del();
    }
    debug_d("\n");

    return 0;
}

int root_device_get_num(void)
{
    int devnum = 0;
	slist_t* node      = NULL;
	device_link_t* obj = NULL;

    if(!root_ctl.dev_head){
        return 0;
    }
	slist_for_each(node,(root_ctl.dev_head))
	{
		obj = slist_entry(node,device_link_t,e_tail);
		if(obj){
            devnum++;
        }
    }

    return devnum ;
}

device_link_t * root_device_find_byindex(int index)
{
    int find_ret = 0;
    int len = 0;
	slist_t* node;
	device_link_t * obj = NULL;

    if(!root_ctl.dev_head){
        debug_e("e_head empty.\n");
        return NULL;
    }

	slist_for_each(node,(root_ctl.dev_head))
	{
		obj = slist_entry(node,device_link_t, e_tail);
		if(obj)
        {
            if(len == index)
            {
                debug_e("find=%s\n",obj->e_attr.name);
                find_ret = 1;
                break;
            }
		}
        len++;
	}

    if(find_ret){
        return obj;
    }else{
        return NULL;
    }
}

static int root_page_add(char* name,char* id,char* type,char* subtype,dev_info_t* dev)
{
    int title_len = 0;
    int txt_len   = 0;
    root_link_t * obj = NULL;

    if((!name)||(!dev)||(!type)||(!subtype)){
        return -1;
    }

    if(!root_ctl.e_head){
        return -1;
    }

    obj = (root_link_t *)malloc(sizeof(root_link_t));
    if(obj == NULL){
        debug_e("obj err\n");
        return -1;
    }
    memset(obj, 0, sizeof(root_link_t));
    slist_init(&(obj->e_tail));
    //**************************************************
    memset(obj->e_attr.name,'\0',R_N_LEN);
    snprintf(obj->e_attr.name,R_N_LEN,"%s",name);

    memset(obj->e_attr.id,0,R_N_LEN);
    snprintf(obj->e_attr.id,R_N_LEN,"%s",id);

    memset(obj->e_attr.type,0,R_N_LEN);
    snprintf(obj->e_attr.type,R_N_LEN,"%s",type);

    memset(obj->e_attr.subtype,0,R_N_LEN);
    snprintf(obj->e_attr.subtype,R_N_LEN,"%s",subtype);
    //**************************************************

    obj->e_attr.dev            = dev;
    obj->e_attr.dev->method    = dev->method;
    obj->e_attr.dev->priv_data = dev->priv_data;
    //**************************************************
    root_ctl.len++;
    slist_add_tail(root_ctl.e_head,&(obj->e_tail));
    //**************************************************
    if((!strcmp(name,PAGE_SETTING_NAME))||
       (!strcmp(name,PAGE_HOME_NAME)))
    {

    }
    else{
        root_device_add(name,id,type,subtype);
    }
    //**************************************************
    debug_d("add page:%s\n",obj->e_attr.name);
    page_install(obj->e_attr.name,obj->e_attr.dev->method,obj->e_attr.dev->priv_data);
    //**************************************************

    return 0;
}

int root_page_del(char* name,char* id)
{
	int ret = 0;
	slist_t* node;
	root_link_t * obj = NULL;

    page_uninstall(name);

    if(!root_ctl.e_head){
        return -1;
    }
    //********************************************************
	if(slist_isempty(root_ctl.e_head)){
		debug_e("list empty.\n");
		return -1;
	}
    //********************************************************
	slist_for_each(node, (root_ctl.e_head))
	{
		obj = slist_entry(node, root_link_t, e_tail);
		if(obj)
        {
            if(!strcmp(obj->e_attr.name,name))
            {
                ret = 1;
                break;
            }
            if(!strcmp(obj->e_attr.id,id))
            {
                ret = 1;
                break;
            }
		}
	}
    //********************************************************
	if(ret){
        debug_d("del page:%s\n",obj->e_attr.name);
		slist_remove(root_ctl.e_head, &(obj->e_tail));
		root_ctl.len--;

        debug_d("\n");
        if(obj->e_attr.dev->method){
            free(obj->e_attr.dev->method);
            obj->e_attr.dev->method = NULL;
        }
        debug_d("\n");

        if(obj->e_attr.dev->priv_data){
            free(obj->e_attr.dev->priv_data);
            obj->e_attr.dev->priv_data = NULL;
        }
        debug_d("\n");
        if(obj->e_attr.dev){
            free(obj->e_attr.dev);
            obj->e_attr.dev = NULL;
        }
        debug_d("\n");

        free(obj);
        obj = NULL;
        debug_d("\n");
	}
    //********************************************************

	return 0;
}

int root_page_device_trav(void)
{
    int find_ret = 0;
	slist_t* node;
	root_link_t* obj = NULL;

    if(!root_ctl.e_head){
        return -1;
    }

	slist_for_each(node,(root_ctl.e_head))
	{
		obj = slist_entry(node,root_link_t,e_tail);
		if(obj)
        {
            debug_d("add device name:%s\n",obj->e_attr.name);
            debug_d("add device type:%s\n",obj->e_attr.type);
            debug_d("add device subt:%s\n",obj->e_attr.subtype);

            if(!strcmp(obj->e_attr.type,"0xE1")) //洗碗机/E1
            {
                dev_washer_t* washer = NULL;
                washer = (dev_washer_t*)obj->e_attr.dev->priv_data;
                root_page_add_devwasher(washer);
                debug_d("add washer\n");
            }
            else if(!strcmp(obj->e_attr.type,"0xE2")) //电热/E2
            {
    
            }
            else if(!strcmp(obj->e_attr.type,"0xE3")) //燃热/E3
            {
                
            }
            else if(!strcmp(obj->e_attr.type,"0xED")) //软水机/净水机/中央净水机/ED
            {
                if(!strcmp(obj->e_attr.subtype,"1086"))
                {
                    ui_dev_purifier_t* puri = NULL;
                    puri = (ui_dev_purifier_t*)obj->e_attr.dev->priv_data;
                    root_page_add_devpuri(puri);
                    debug_d("add puri\n");
                }
            }
            else if(!strcmp(obj->e_attr.type,"0xB6")) //烟机/B6
            {
    
            }
            else if((!strcmp(obj->e_attr.type,"0x21"))||
                    (!strcmp(obj->e_attr.type,"0x14")))
            {
                debug_d("add device subt:%s\n",obj->e_attr.subtype);
                if((!strcmp(obj->e_attr.subtype,"3006"))  ||
                    (!strcmp(obj->e_attr.subtype,"3007")) ||
                    (!strcmp(obj->e_attr.subtype,"3008")) ||
                    (!strcmp(obj->e_attr.subtype,"3009")) ||
                    (!strcmp(obj->e_attr.subtype,"3014")) ||
                    (!strcmp(obj->e_attr.subtype,"3015")) )//dwled
                {
                    ui_dev_dwled_t* dwled = NULL;
                    dwled = (ui_dev_dwled_t*)obj->e_attr.dev->priv_data;
                    root_page_add_dwled(dwled);
                    debug_d("add dwled\n");
                }
                else if((!strcmp(obj->e_attr.subtype,"3005"))||
                        (!strcmp(obj->e_attr.subtype,"3013")))//swled
                {
                    ui_dev_swled_t* swled = NULL;
                    swled = (ui_dev_swled_t*)obj->e_attr.dev->priv_data;
                    root_page_add_swled(swled);
                    debug_d("add swled\n");
                }
                else if(!strcmp(obj->e_attr.subtype,"0"))//mc
                {
                    ui_dev_mc_t* mc = NULL;
                    mc = (ui_dev_mc_t*)obj->e_attr.dev->priv_data;
                    root_page_add_devmc(mc);
                    debug_d("add mc\n");
                }
                else if((!strcmp(obj->e_attr.subtype,"3043")))//oc
                {
                    ui_dev_oc_t* oc = NULL;
                    oc = (ui_dev_oc_t*)obj->e_attr.dev->priv_data;
                    root_page_add_devoc(oc);
                    debug_d("add oc\n");
                }      
                else if((!strcmp(obj->e_attr.subtype,"3053")))//jc
                {
                    ui_dev_jc_t* jc = NULL;
                    jc = (ui_dev_jc_t*)obj->e_attr.dev->priv_data;
                    root_page_add_devjc(jc);
                    debug_d("add jcc\n");
                }
            }
		}
	}

    return 0;
}

int root_page_get_num(void)
{
    root_link_t * obj = NULL;

    if(!root_ctl.e_head){
        return 0;
    }

    return root_ctl.len;
}

root_link_t * root_page_find_index(int index)
{
    int find_ret = 0;
    int len = 0;
	slist_t* node;
	root_link_t * obj = NULL;

    if(!root_ctl.e_head){
        debug_e("e_head empty.\n");
        return NULL;
    }

	if(slist_isempty(root_ctl.e_head)){
		debug_e("list empty.\n");
		return NULL;
	}

	slist_for_each(node,(root_ctl.e_head))
	{
		obj = slist_entry(node, root_link_t, e_tail);
		if(obj)
        {
            if(len == index){
                find_ret = 1;
                break;
            }
		}
        len++;
	}

    if(find_ret){
        return obj;
    }else{
        return NULL;
    }
}

int root_page_device_is_reg(const char* id)
{
    int ret = 0;
	slist_t* node     = NULL;
	root_link_t * obj = NULL;

    if(!id){
        return 0;
    }

    if(!root_ctl.e_head){
        debug_e("e_head empty.\n");
        return 0;
    }

	if(slist_isempty(root_ctl.e_head)){
		debug_e("list empty.\n");
		return 0;
	}

	slist_for_each(node,(root_ctl.e_head))
	{
		obj = slist_entry(node,root_link_t,e_tail);
		if(obj)
        {
            if(!strcmp(obj->e_attr.id,id))
            {
                debug_e("find=%s\n",obj->e_attr.name);
                debug_e("find=%s\n",obj->e_attr.id);
                ret = 1;
                break;
            }
		}
	}

    return ret;
}

static root_link_t * root_page_find_name(const char* name)
{
    int find_ret = 0;
	slist_t* node;
	root_link_t * obj = NULL;

    if(!name){
        return NULL;
    }

    if(!root_ctl.e_head){
        debug_e("e_head empty.\n");
        return NULL;
    }

	if(slist_isempty(root_ctl.e_head)){
		debug_e("list empty.\n");
		return NULL;
	}

	slist_for_each(node,(root_ctl.e_head))
	{
		obj = slist_entry(node, root_link_t, e_tail);
		if(obj){
            if(!strcmp(obj->e_attr.name,name))
            {
                debug_e("find=%s\n",obj->e_attr.name);
                find_ret = 1;
                break;
            }
		}
	}

    if(find_ret){
        return obj;
    }else{
        return NULL;
    }
}

root_link_t * root_page_find_bydevid(const char* devid)
{
    int find_ret = 0;
	slist_t* node;
	root_link_t * obj = NULL;

    if(!devid){
        debug_e("id err\n");
        return NULL;
    }

    if(!root_ctl.e_head){
        debug_e("head empty.\n");
        return NULL;
    }

	if(slist_isempty(root_ctl.e_head)){
		debug_e("list empty.\n");
		return NULL;
	}
	slist_for_each(node,(root_ctl.e_head))
	{
		obj = slist_entry(node, root_link_t,e_tail);
		if(obj){
            if(!strcmp(obj->e_attr.id,devid))
            {
                // debug_e("find=%s\n",obj->e_attr.id);
                find_ret = 1;
                break;
            }
		}
	}

    if(find_ret){
        return obj;
    }else{
        return NULL;
    }
}

root_link_t* root_page_find_by_type(const char* type,const char* subtype)
{
    int find_ret = 0;
	slist_t* node;
	root_link_t * obj = NULL;

    if((!type)||(!subtype)){
        return NULL;
    }

    if(!root_ctl.e_head){
        debug_e("e_head empty.\n");
        return NULL;
    }

	if(slist_isempty(root_ctl.e_head)){
		debug_e("list empty.\n");
		return NULL;
	}

	slist_for_each(node,(root_ctl.e_head))
	{
		obj = slist_entry(node,root_link_t,e_tail);
		if(obj)
        {
            if(!strcmp(obj->e_attr.type,type))
            {
                if(!strcmp(obj->e_attr.subtype,subtype))  
                {
                    find_ret = 1;
                    break;
                }  
            }
		}
	}

    if(find_ret){
        return obj;
    }else{
        return NULL;
    }
}

static int root_page_del_bydevid(const char* devname,const char* devid)
{
    debug_d("delname=%s\n",devname);
    debug_d("delid=%s\n",devid);
    if((!devname)||(devid)){
        return -1;
    }





    return 0;
}

static int root_page_push(char * name,page_load_anim_t type,page_vtable_t* pdev)
{
    debug_d("name=%s\n",name);

    if(!name){
        return -1;
    }
    page_push_anim(name,type);
    return 0;
}

static int root_page_pop(char * name,page_load_anim_t type,page_vtable_t* pdev)
{
    debug_d("name=%s\n",name);

    if(!name){
        return -1;
    }
    page_pop_anim(type);
    return 0;
}

static int root_page_pop2(char * name,page_load_anim_t type,page_vtable_t* pdev)
{
    debug_d("name=%s\n",name);

    if(!name){
        return -1;
    }
    page_pop_anim_name(type,name);
    return 0;
}

static int root_page_add_all(void)
{
    static dev_info_t set;
    set.method    = lv_page_setting_create();
    set.priv_data = NULL;
    root_page_add(PAGE_SETTING_NAME,"0x00","0x00","0x00",&set);   //0
    //********************************************************
    static dev_info_t root;
    root.method    = lv_page_root_create();
    root.priv_data = NULL;
    root_page_add(PAGE_HOME_NAME,"0x01","0x01","0x01",&root);  //1
    //********************************************************

    return 0;
}

int root_page_add_all_device(void)
{
    #if 1 //for test
    ui_puri_data_t puri;

    memset(&puri,0,sizeof(ui_puri_data_t));

    puri.status = DEV_WORK;//DEV_OFF_LINE; DEV_OFF DEV_WORK
    puri.workstatus = PURIFIER_STAT_ERR;

    puri.is_exist_heat = 1;
    puri.is_exist_wash = 1;

    puri.is_exist_tds  = 0;
    puri.is_exist_rofilter = 0;

    puri.filter_num = 3;

    puri.jstds = 90;//196;
    puri.cstds = 200;//196;

    sprintf(puri.f_info[0].name,"%s","耗材1");
    puri.f_info[0].life = 180;

    sprintf(puri.f_info[1].name,"%s","耗材2");
    puri.f_info[1].life = 200;  

    sprintf(puri.f_info[2].name,"%s","耗材3");
    puri.f_info[2].life = 0;

    snprintf(puri.devname,   128,"%s","净水机");
    snprintf(puri.devid,     128,"%s","js11");
    snprintf(puri.devtype,   128,"%s","0xED");
    snprintf(puri.devsubtype,128,"%s","1086");

    root_page_add_puri_device(&puri);
    //****************************************
    ui_dwled_data_t dw_data;
    memset(&dw_data,0,sizeof(ui_dwled_data_t));

    dw_data.status = 0;
    dw_data.onoff  = 0;

    dw_data.brightness = 50;
    dw_data.min_bright = 0;
    dw_data.max_bright = 100;

    dw_data.color_temp    = 60;
    dw_data.min_colortemp = 0;
    dw_data.max_colortemp = 100;

    snprintf(dw_data.devname,   128,"%s","双色灯");
    snprintf(dw_data.devid,     128,"%s","dw11");
    snprintf(dw_data.devtype,   128,"%s","0x21");
    snprintf(dw_data.devsubtype,128,"%s","3006");

    root_page_add_dwled_device(&dw_data);

    //****************************************
    ui_swled_data_t sw_data;
    memset(&sw_data,0,sizeof(ui_swled_data_t));

    sw_data.status = 0;
    sw_data.onoff  = 0;
    sw_data.brightness = 50;
    sw_data.min_bright = 0;
    sw_data.max_bright = 100;

    snprintf(sw_data.devname,   128,"%s","单色灯");
    snprintf(sw_data.devid,     128,"%s","sw11");
    snprintf(sw_data.devtype,   128,"%s","0x21");
    snprintf(sw_data.devsubtype,128,"%s","3005");

    root_page_add_swled_device(&sw_data);
    //****************************************
    ui_mc_data_t dev_mc;

    snprintf(dev_mc.devname,   128,"%s","梦幻帘");
    snprintf(dev_mc.devid,     128,"%s","mc22");
    snprintf(dev_mc.devtype,   128,"%s","0x21");
    snprintf(dev_mc.devsubtype,128,"%s","0");

    dev_mc.is_notrip  = 1;
    dev_mc.workstatus = 0; 
    dev_mc.status     = 0;
    dev_mc.old_val    = 100;
    dev_mc.target_val = 100;

    dev_mc.cur_val =  100;
    dev_mc.min     = 0;
    dev_mc.max     = 100;
    root_page_add_mc_device(&dev_mc);
    //********************************************************
    ui_oc_data_t dev_oc;

    snprintf(dev_oc.devname,   128,"%s","开合帘");
    snprintf(dev_oc.devid,     128,"%s","oc22");
    snprintf(dev_oc.devtype,   128,"%s","0x21");
    snprintf(dev_oc.devsubtype,128,"%s","3043");

    dev_oc.is_notrip  = 0;
    dev_oc.workstatus = 0; 
    dev_oc.status     = 0;
    dev_oc.old_val    = 100;
    dev_oc.target_val = 100;

    dev_oc.cur_val =  100;
    dev_oc.min     = 0;
    dev_oc.max     = 100;
    root_page_add_oc_device(&dev_oc);
    //********************************************************
    // ui_jc_data_t dev_jc;

    // snprintf(dev_jc.devname,   128,"%s","卷帘");
    // snprintf(dev_jc.devid,     128,"%s","jc22");
    // snprintf(dev_jc.devtype,   128,"%s","0x21");
    // snprintf(dev_jc.devsubtype,128,"%s","3053");

    // dev_jc.is_notrip  = 0;
    // dev_jc.workstatus = 0; 
    // dev_jc.status     = 0;
    // dev_jc.old_val    = 100;
    // dev_jc.target_val = 100;

    // dev_jc.cur_val =  100;
    // dev_jc.min     = 0;
    // dev_jc.max     = 100;
    // root_page_add_jc_device(&dev_jc);
    //********************************************************
    // dev_washer_t washer;

    // snprintf(washer.data.base.devname,   64,"%s","洗碗机");
    // snprintf(washer.data.base.devid,     20,"%s","washer");
    // snprintf(washer.data.base.devtype,   12,"%s","0xE1");
    // snprintf(washer.data.base.devsubtype,12,"%s","3053");

    // root_page_add_washer_device(&washer);
    //********************************************************
    #endif
    //********************************************************
    int dev_num = 0;
    dev_num = root_page_get_num() - 3;
    pt_dev_num_set(dev_num);
    //********************************************************

    return 0;
}

int root_page_del_device(char* name,char* id)
{
    if((!name)||(!id)){
        return -1;
    }

    root_ctl.cur_id = PAGE_HOME_ID;
    page_pop_anim_name(LOAD_ANIM_MOVE_LEFT,"home");

    root_device_del_bydevid(id);

    root_page_del(name,id);

    int dev_num = 0;
    dev_num = root_page_get_num() - 3;
    pt_dev_num_set(dev_num);

    return 0;
}

int root_page_del_all_device(void)
{
    int i   = 0;
    int num = 0;

    device_link_t* obj = NULL;

    debug_d("id=%d\n",root_ctl.cur_id);
    
    if(root_ctl.cur_id != PAGE_HOME_ID)
    {
        root_ctl.cur_id = PAGE_HOME_ID;
        page_pop_anim_name(LOAD_ANIM_MOVE_LEFT,"home");
    }

    num = root_device_get_num();
    for(i=0;i<num;i++)
    {
        obj = root_device_find_byindex(i);
        if(!obj){
            continue;
        }

        debug_d("delname=%s\n",obj->e_attr.name);
        root_page_del(obj->e_attr.name,obj->e_attr.id);
    }

    debug_d("\n");
    root_device_del_all();
    debug_d("\n");

    int dev_num = 0;
    dev_num = root_page_get_num() - 3;
    pt_dev_num_set(dev_num);

	return 0;
}

int root_page_add_dwled_device(ui_dwled_data_t* dev_dwled)
{
    dev_info_t* dev = NULL;

    if(root_page_device_is_reg(dev_dwled->devid))
    {
        return 0;
    }

    dev = dev_dwled_reg(dev_dwled);
    if(!dev){
        debug_d("reg err\n");
        return -1;
    }

    root_page_add(dev_dwled->devname,dev_dwled->devid,dev_dwled->devtype,dev_dwled->devsubtype,dev);

    return 0;
}

int root_page_add_swled_device(ui_swled_data_t* dev_swled)
{
    dev_info_t* dev = NULL;

    if(root_page_device_is_reg(dev_swled->devid))
    {
        return 0;
    }

    dev = dev_swled_reg(dev_swled);
    if(!dev){
        debug_d("reg err\n");
        return -1;
    }

    root_page_add(dev_swled->devname,dev_swled->devid,dev_swled->devtype,dev_swled->devsubtype,dev);

    return 0;
}

int root_page_add_mc_device(ui_mc_data_t* dev_mc)
{
    dev_info_t* dev = NULL;

    if(root_page_device_is_reg(dev_mc->devid))
    {
        debug_e("page is reg\n");
        return 0;
    }

    dev = dev_mc_reg(dev_mc);
    if(!dev){
        debug_d("reg err\n");
        return -1;
    }

    root_page_add(dev_mc->devname,dev_mc->devid,dev_mc->devtype,dev_mc->devsubtype,dev);

    return 0;
}

int root_page_add_oc_device(ui_oc_data_t* dev_oc)
{
    dev_info_t* dev = NULL;

    if(!dev_oc){
        return -1;
    }

    if(root_page_device_is_reg(dev_oc->devid))
    {
        return 0;
    }

    dev = dev_oc_reg(dev_oc);
    if(!dev){
        debug_d("reg err\n");
        return -1;
    }

    root_page_add(dev_oc->devname,dev_oc->devid,dev_oc->devtype,dev_oc->devsubtype,dev);

    return 0;
}

int root_page_add_jc_device(ui_jc_data_t* dev_jc)
{
    dev_info_t* dev = NULL;

    if(!dev_jc){
        return -1;
    }

    if(root_page_device_is_reg(dev_jc->devid))
    {
        return 0;
    }

    dev = dev_jc_reg(dev_jc);
    if(!dev){
        debug_d("reg err\n");
        return -1;
    }

    root_page_add(dev_jc->devname,dev_jc->devid,dev_jc->devtype,dev_jc->devsubtype,dev);

    return 0;
}

int root_page_add_puri_device(ui_puri_data_t* puri)
{
    dev_info_t* dev = NULL;

    if(!puri){
        return -1;
    }

    if(root_page_device_is_reg(puri->devid))
    {
        return 0;
    }

    dev = dev_purifier_reg(puri);
    if(!dev){
        debug_d("reg err\n");
        return -1;
    }

    root_page_add(puri->devname,puri->devid,puri->devtype,puri->devsubtype,dev);

    return 0;
}



int root_page_add_washer_device(data_washer_t* dev_data)
{
    dev_info_t* dev = NULL;

    if(!dev_data){
        return -1;
    }

    if(root_page_device_is_reg(dev_data->base.devid))
    {
        return 0;
    }

    dev = dev_washer_reg(dev_data);
    if(!dev){
        debug_d("reg err\n");
        return -1;
    }

    root_page_add(dev_data->base.devname,dev_data->base.devid,dev_data->base.devtype,dev_data->base.devsubtype,dev);

    return 0;
}

#if 0
int root_page_add_rangehood_device(ui_rangehood_data_t* rangehood)
{
    dev_info_t* dev = NULL;

    if(!rangehood){
        return -1;
    }

    if(root_page_device_is_reg(rangehood->devid))
    {
        return 0;
    }
    
    dev = dev_rangehood_reg(rangehood);
    if(!dev){
        debug_d("reg err\n");
        return -1;
    }

    root_page_add(rangehood->devname,rangehood->devid,rangehood->devtype,rangehood->devsubtype,dev);

    return 0;
}
#endif

dev_info_t* root_page_reg_msg_mater(char* name,char* consum_name,char* err_code,char* err_info)
{
    dev_info_t* msg_mater = NULL;
    ui_mater_data_t data;

    if((!name)||(!consum_name)||(!err_code)||(!err_info)){
        return NULL;
    }

    memset(&data,0,sizeof(ui_mater_data_t));

    snprintf(&data.dev_name,       sizeof(data.dev_name),       "%s",name);
    snprintf(&data.dev_consum_name,sizeof(data.dev_consum_name),"%s",consum_name);
    snprintf(&data.dev_err_code,   sizeof(data.dev_err_code),   "%s",err_code);
    snprintf(&data.dev_err_info,   sizeof(data.dev_err_info),   "%s",err_info);

    msg_mater = msg_mater_reg(&data);

    return msg_mater;
}

dev_info_t* root_page_reg_msg_err(char* name,char* consum_name,char* err_code,char* err_info)
{
    dev_info_t* msg_err = NULL;
    ui_err_data_t data;

    if((!name)||(!consum_name)||(!err_code)||(!err_info)){
        return -1;
    }

    memset(&data,0,sizeof(ui_err_data_t));

    snprintf(&data.dev_name,       sizeof(data.dev_name),       "%s",name);
    snprintf(&data.dev_consum_name,sizeof(data.dev_consum_name),"%s",consum_name);
    snprintf(&data.dev_err_code,   sizeof(data.dev_err_code),   "%s",err_code);
    snprintf(&data.dev_err_info,   sizeof(data.dev_err_info),   "%s",err_info);

    msg_err = msg_err_reg(&data);

    return msg_err;
}

static int root_page_enter_logo(void)
{
    page_install("logo",lv_page_startup_create(),NULL);
    page_push_anim("logo",LOAD_ANIM_NONE);

    return 0;
}

static int root_msg_e1(void)
{
    // pop_win_load("msg_e1",lv_page_msg_e1_create());
    return 0;
}
static int root_msg_err(msg_notify_t* msg)
{
    static int cnt = 0;
    char reg_name[24];

    dev_info_t* m_err = NULL;
    char* name        = NULL;
    char* consum_name = NULL;
    char* err_code    = NULL;
    char* err_info    = NULL;

    event_info_t* e_i = NULL;

    if(!msg){
        debug_e("err\n");
        return -1;
    }
    if(!msg->para){
        debug_e("err\n");
        return -1;
    }

    e_i  = (event_info_t*)msg->para;

    name        = e_i->dev_name;
    consum_name = e_i->dev_consum_name;
    err_code    = e_i->dev_err_code;
    err_info    = e_i->dev_err_info;

    if((!name)||(!consum_name)||(!err_code)||(!err_info)){
        return -1;
    }

    m_err = root_page_reg_msg_err(name,consum_name,err_code,err_info);
    if(!m_err){
        return -1;
    }

    memset(reg_name,0,sizeof(reg_name));
    snprintf(reg_name,sizeof(reg_name),"err_%d",cnt++);

    pop_win_load(reg_name,m_err->method,m_err->priv_data);

    if(msg->para)
    {
        psram_free(msg->para);
        msg->para = NULL;
    }

    return 0;
}
static int root_msg_mater(msg_notify_t* msg)
{
    char reg_name[24];
    static int cnt = 0;
    dev_info_t* mater = NULL;
    char* name        = NULL;
    char* consum_name = NULL;
    char* err_code    = NULL;
    char* err_info    = NULL;

    event_info_t* e_i = NULL;

    if(!msg){
        return -1;
    }
    if(!msg->para){
        return -1;
    }

    e_i  = (event_info_t*)msg->para;

    name        = e_i->dev_name;
    consum_name = e_i->dev_consum_name;
    err_code    = e_i->dev_err_code;
    err_info    = e_i->dev_err_info;

    if((!name)||(!consum_name)||(!err_code)||(!err_info)){
        debug_e("err\n");
        return -1;
    }   

    mater = root_page_reg_msg_mater(name,consum_name,err_code,err_info);
    if(!mater){
        debug_e("err\n");
        return -1;
    }

    memset(reg_name,0,sizeof(reg_name));
    snprintf(reg_name,sizeof(reg_name),"mater_%d",cnt++);

    pop_win_load(reg_name,mater->method,mater->priv_data);

    if(msg->para)
    {
        psram_free(msg->para);
        msg->para = NULL;
    }

    return 0;
}
static int root_msg_telephone(void)
{
    // pop_win_load("msg_tele",lv_page_msg_telephone_create());
    return 0;
}
static int root_msg_update(void)
{
    // pop_win_load("msg_update",lv_page_msg_update_create());
    return 0;
}    
static int root_voice_input(void)
{
    // pop_win_load("voice_input",lv_page_voice_input_create());
    return 0;
}   
static int root_voice_meeting(void)
{
    // pop_win_load("voice_meeting",lv_page_voice_meeting_create());
    return 0;
}      
static int root_voice_output(void)
{
    // pop_win_load("voice_output",lv_page_voice_output_create());
    return 0;
}       
static int root_voice_sunny(void)
{
    // pop_win_load("voice_sunny",lv_page_voice_sunny_create());
    return 0;
}       
static int root_voice_wkup(void)
{
    // pop_win_load("voice_wkup",lv_page_voice_wkup_create());
    return 0;
}       

static int root_enter_idle(void)
{


    return 0;
}

static int root_screen_off(void)
{
    // if(root_no_scr_off_flag_get())
    //     return 0;
    // int cur_bright = pt_bright_get();
    // pt_last_bright_set(cur_bright);
    // pt_bright_set(0);
    // pt_scr_off_flag_set(1); //set scr off flag
    // //os_printf("set scr_off_flag and set last bright:%d\n",cur_bright);

    return 0;
}

static int root_screen_on(void)
{
    // int cur_bright = pt_last_bright_get();
    // pt_bright_set(cur_bright);
    // pt_scr_off_flag_set(0); //set scr off flag
    // //os_printf("set scr_off_flag and set last bright:%d\n",cur_bright);

    return 0;
}

int root_exit_idle(void)
{
    root_link_t *obj = NULL;

    debug_d("id=%d\n",root_ctl.cur_id);


    obj = root_page_find_index(root_ctl.cur_id);
    if(!obj){
        debug_e("find err\n");
        return -1;
    }

    root_page_pop(obj->e_attr.name,LOAD_ANIM_MOVE_RIGHT,obj->e_attr.dev->method);  
    root_gesture_enable();

    if(root_ctl.cur_id == PAGE_SETTING_ID)
    {

    }
    else if(root_ctl.cur_id == PAGE_HOME_ID && pt_dev_num_get() <= 1)
    {

    }
    else{

    }

    root_ctl.is_idle = 0;

    return 0;
}

int cls_bright_sw = 0; //靠近亮屏开关 

int set_cls_bright_flag(int flag)
{
    cls_bright_sw = flag;
    return flag;
}

static int get_cls_bright_flag()
{
    return cls_bright_sw;
}

static int root_human_coming(void)
{
    debug_d("human coming,screen on\n");

    if(get_cls_bright_flag())
    {
        int cur_bright = 0;
        cur_bright = pt_bright_get();

        pt_bright_set(cur_bright);
    }


    return 0;
}

static int root_human_leave(void)
{


    return 0;
}


static int root_light_update(void)
{


    return 0;
}

static int root_msg_key_left(msg_notify_t* msg)
{
#if 0
    char* key= "left";

    if(!btn_left_is_radio())
    {
        uint8_t sw = 0;
        if(relay_read_status(POROS_RELAY1)){
            relay_set_status(POROS_RELAY1,0);
        }else{
            relay_set_status(POROS_RELAY1,1);
            sw = 1;
        }
        st_scr_para scr;
        memset(&scr,0xFF,sizeof(scr));
        scr.btn_stat.bits.l_btn_stat = sw & 0x03;
        pt_ipc_send_msg(IPC_UPDATE_SCR_STAT,&scr,sizeof(scr));

    }
    else
    {
        if(!pt_network_get())
            return -1;

        pt_ipc_send_msg(IPC_BTN_CTL,key,strlen(key));
    }
#endif

    return 0;
}

static int root_msg_key_middle(msg_notify_t* msg)
{
#if 0
    char* key= "middle";

    if(!btn_middle_is_radio())
    {
        uint8_t sw = 0;
        if(relay_read_status(POROS_RELAY2)){
            relay_set_status(POROS_RELAY2,0);
        }else{
            relay_set_status(POROS_RELAY2,1);
            sw = 1;
        }
        st_scr_para scr;
        memset(&scr,0xFF,sizeof(scr));
        scr.btn_stat.bits.m_btn_stat = sw & 0x03;
        pt_ipc_send_msg(IPC_UPDATE_SCR_STAT,&scr,sizeof(scr));

    }else{
        
        if(!pt_network_get())
            return -1;

        pt_ipc_send_msg(IPC_BTN_CTL,key,strlen(key));
    }
#endif

    return 0;
}

static int root_msg_key_right(msg_notify_t* msg)
{
#if 0
    char* key= "right";

    if(!btn_right_is_radio())
    {
        uint8_t sw = 0;
        if(relay_read_status(POROS_RELAY3)){
            relay_set_status(POROS_RELAY3,0);
        }else{
            relay_set_status(POROS_RELAY3,1);
            sw = 1;
        }

        st_scr_para scr;
        memset(&scr,0xFF,sizeof(scr));
        scr.btn_stat.bits.r_btn_stat = sw & 0x03;
        pt_ipc_send_msg(IPC_UPDATE_SCR_STAT,&scr,sizeof(scr));

    }else{

        if(!pt_network_get())
            return -1;
    
        pt_ipc_send_msg(IPC_BTN_CTL,key,strlen(key));    
    }
#endif

    return 0;
}

static void root_ctl_time_callback(struct _lv_timer_t * t)
{
    int ret = -1;
    msg_notify_t msg_recv;
    ret = msg_queue_recv(&msg_recv);
    if(ret != 0){
        return ;
    }

    switch(msg_recv.cmd){
    case MSG_DOWNLOAD_FIRMWARE:
    {
        debug_d("fire down ok\n");
        // page_install("setting_sys_update", lv_page_setting_sys_update_create(),NULL);
        // page_push_anim("setting_sys_update",LOAD_ANIM_MOVE_LEFT);
        break;
    }   
    case MSG_SYS_UP_ERR:
    {
        debug_d("sys up err\n");
        // page_install("sys_up_err", lv_page_setting_up_err_create(),NULL);
        // page_push_anim("sys_up_err",LOAD_ANIM_MOVE_LEFT);
        break;
    }     
    case MSG_SYS_UP_SUCCEED:
    {
        debug_d("sys up ok,reboot\n");

        // pt_reboot();
        break;
    } 
    case MSG_E1:
    {
        debug_d("e1\n");
        root_msg_e1();
        break;
    }
    case MSG_ERR:
    {
        debug_d("err\n");
        root_msg_err(&msg_recv);
        break;
    }
    case MSG_MATER:
    {
        debug_d("mater\n");
        root_msg_mater(&msg_recv);
        break;
    }
    case MSG_TELEPHONE:
    {
        debug_d("telephone\n");
        root_msg_telephone();
        break;
    }
    case MSG_UPDATE:
    {
        debug_d("update\n");
        root_msg_update();
        break;
    }
    case MSG_VOICE_INPUT:
    {
        debug_d("vinput\n");
        root_voice_input();
        break;
    }
    case MSG_VOICE_MEETING:
    {
        debug_d("vmeeting\n");
        root_voice_meeting();
        break;
    }
    case MSG_VOICE_OUTPUT:
    {
        debug_d("voutput\n");
        root_voice_output();
        break;
    }
    case MSG_VOICE_SUNNY:
    {
        debug_d("vsuny\n");
        root_voice_sunny();
        break;
    }
    case MSG_VOICE_WKUP:
    {
        debug_d("vwkup\n");
        root_voice_wkup();
        break;
    }
    case MSG_KEY_LEFT:
    {

        break;
    }
    case MSG_KEY_RIGHT:
    {
  
        break;
    }
    case MSG_KEY_MID:
    {

        break;
    }
    case MSG_IDLE_EVENT:
    {
        root_enter_idle();
        break;
    }
    case MSG_HUMAN_COMING:
    {
        root_human_coming();
        break;
    }
    case MSG_HUMAN_LEAVE:
    {
        root_human_leave();
        break;
    }
    case MSG_LIGHT_UPDATE:
    {
        root_light_update(); 
        break;
    }
    case MSG_SCR_OFF:
    {
        root_screen_off();
        break;
    }
    default:break;
    }
}


int root_gesture_left(void)
{
    int num = 0;
    root_link_t *  obj = NULL;

    debug_d("id=%d\n",root_ctl.cur_id);


    return 0;
}

int root_gesture_right(void)
{
    int num = 0;
    root_link_t *  obj = NULL;

    debug_d("id=%d\n",root_ctl.cur_id);

    return 0;
}

int root_gesture_top(void)
{
    root_link_t*  obj = NULL;

    debug_d("id=%d\n",root_ctl.cur_id);

    if(root_ctl.cur_id == PAGE_SETTING_ID)
    {
        obj = root_page_find_index(PAGE_HOME_ID);
        if(!obj){
            debug_e("find err\n");
            return -1;
        }
        
        root_page_pop(obj->e_attr.name,LOAD_ANIM_MOVE_BOTTOM,obj->e_attr.dev->method);
        root_ctl.cur_id = PAGE_HOME_ID;
    }

    return 0;
}

int root_gesture_bottom(void)
{
    debug_d("id=%d\n",root_ctl.cur_id);

    if(root_ctl.cur_id == PAGE_SETTING_ID)
    {

    }
    else
    {

        root_ctl.cur_id  = PAGE_SETTING_ID;
        root_page_push("setting",LOAD_ANIM_MOVE_BOTTOM,lv_page_setting_create());
    }

    return 0;
}



int root_gesture_state(void)
{
    return root_ctl.gesture_state;
}

int root_gesture_enable(void)
{
    // if(!root_ctl.gesture_state)
    // {
    //     lv_obj_add_event_cb(lv_scr_act(), root_page_gesture_cb, LV_EVENT_GESTURE,NULL);
    //     root_ctl.gesture_state = 1;

    //     debug_d("gesture enable\n");
    // }
    
    return 0;
}

int root_gesture_disable(void)
{
    // if(root_ctl.gesture_state)
    // {
    //     lv_obj_remove_event_cb(lv_scr_act(), root_page_gesture_cb);
    //     root_ctl.gesture_state = 0;

    //     debug_d("gesture disable\n");
    // }
    
    return 0;
}

int root_idle_time_reset(void)
{
    if(!root_ctl.idle_timer)
        return -1;
    if(!root_ctl.scr_off_timer)
        return -1;

    lv_timer_reset(root_ctl.idle_timer);

    lv_timer_reset(root_ctl.scr_off_timer);

    //os_printf("scr_off_flag:%d\n",pt_scr_off_flag_get());
    
    // if(pt_scr_off_flag_get())
    // {
    //     int cur_bright = pt_last_bright_get();
    //     pt_bright_set(cur_bright);
    //     pt_scr_off_flag_set(0);
    //     //os_printf("clr scr_off_flag and set bright:%d\n",cur_bright);
    // }
    return 0;
}


static void root_idle_time_callback(struct _lv_timer_t * t)
{
    //debug_d("idle timeout\n");
    root_send_msg(MSG_IDLE_EVENT,0,0,0,NULL);
}

static void root_scr_off_time_callback(struct _lv_timer_t * t)
{
    //debug_d("idle timeout\n");
    root_send_msg(MSG_SCR_OFF,0,0,0,NULL);
}

#if 1
//never,15s,30s,1min,2min,5min,10min
const static uint32_t scr_off_timer_per[7] = {0xffffffff,15000,30000,60000,120000,300000,600000};
static uint8_t scr_off_timer_type = 0; 

uint8_t root_scr_off_timer_interval_get(void)
{
    return scr_off_timer_type;
}

uint8_t root_scr_off_timer_interval_set(uint8_t val)
{
    if(val > 6)
    {
        return 0;
    }
        
    scr_off_timer_type = val;
    uint32_t interval = 0;

#if 0
    switch(scr_off_timer_type)
    {
        case 0: //never
            root_no_scr_off_flag_set(1);
            interval = 0xFFFFFFFF;
            break;
        case 1: //15sec
            root_no_scr_off_flag_set(0);
            interval = 15000;
            break;
        case 2: //30sec
            root_no_scr_off_flag_set(0);
            interval = 30000;
            break;
        case 3: //1 min
            root_no_scr_off_flag_set(0);
            interval = 60000;
            break;
        case 4: //2min
            root_no_scr_off_flag_set(0);
            interval = 120000;
            break;
        case 5: //5min
            root_no_scr_off_flag_set(0);
            interval = 300000;
            break;
        case 6: //10min
            root_no_scr_off_flag_set(0);
            interval = 600000;
            break;
        default:
            break;
    }
    #else
    interval = scr_off_timer_per[scr_off_timer_type];
    if(0 == scr_off_timer_type)
    {
        root_no_scr_off_flag_set(1);
        #if (CONFIG_SYS_CPU1)
        if(pt_scr_off_flag_get())
            root_screen_on();
        #endif
    }
    else
    {
        root_no_scr_off_flag_set(0);
    }
        
    #endif
    #if (CONFIG_SYS_CPU1)
     if(!root_no_scr_off_flag_get())
     {
        os_printf("set scr_off_timer period:%d\n",interval);
        lv_timer_reset(root_ctl.scr_off_timer);
        lv_timer_set_period(root_ctl.scr_off_timer,interval);
     }
     #endif

    return scr_off_timer_type;
}

static int no_scr_off = 1;

int root_no_scr_off_flag_get(void)
{
    debug_d("no_scr_off=%d\n",no_scr_off);
    return no_scr_off;
}

int root_no_scr_off_flag_set(int val)
{
    no_scr_off = val;
    debug_d("no_scr_off=%d\n",no_scr_off);
    return no_scr_off;
}
#endif

static void root_delay_time_callback(struct _lv_timer_t * t)
{
    if(root_ctl.delay_timer){
        lv_timer_del(root_ctl.delay_timer);
        root_ctl.delay_timer = NULL;
    }

    // debug_d("logo_page_del\n");

    // page_satck_clear(0);

    // debug_d("\n");
    // page_uninstall("logo");

    // debug_d("\n");

}

int root_page_enter_home(page_load_anim_t type)
{
    root_ctl.cur_id = PAGE_HOME_ID;

    root_gesture_enable();

    com_title_create();
    root_page_push(PAGE_HOME_NAME,type,lv_page_root_create());

    if(root_ctl.delay_timer){
        lv_timer_del(root_ctl.delay_timer);
        root_ctl.delay_timer = NULL;
    }

    root_ctl.delay_timer = lv_timer_create(root_delay_time_callback,200,NULL);
    root_ctl.idle_timer  = lv_timer_create(root_idle_time_callback,IDLE_TIME,NULL);

    if(root_scr_off_timer_interval_get())
    {
        root_ctl.scr_off_timer = lv_timer_create(root_scr_off_time_callback,scr_off_timer_per[root_scr_off_timer_interval_get()],NULL);
    }
    else
    {
        root_no_scr_off_flag_set(1);
        root_ctl.scr_off_timer = lv_timer_create(root_scr_off_time_callback,0xffffffff,NULL);
    }

    debug_d("enter home\n");

    return 0;
}
/*******************************************************/
static void root_early_time_callback(struct _lv_timer_t * t)
{
    if(!root_ctl.early_timer){
        return ;
    }

    if(root_ctl.early_timer){
        lv_timer_del(root_ctl.early_timer);
        root_ctl.early_timer = NULL;
    }

    root_first_show_logo();
}

int root_ctl_preinit(void)
{
    memset(&root_ctl,0,sizeof(root_ctl_t));

    root_ctl.gesture_state = 0;
    root_ctl.cur_id        = PAGE_HOME_ID;
    root_ctl.is_idle       = 0;
    root_ctl.len           = 0;
    root_ctl.e_head        = NULL;
    root_ctl.time          = NULL;
    root_ctl.idle_timer    = NULL;
    root_ctl.scr_off_timer = NULL;

    root_ctl.early_timer   = lv_timer_create(root_early_time_callback,1000,NULL);

    return 0;
}

int root_first_show_logo(void)
{
    get_sys_date();
    get_sys_time();

    pt_btn_init_para();
    ui_msg_review_init();
    msg_info_init();
    msg_queue_init();
    cmd_queue_init();
    img_queue_init();
    scene_info_init();
    history_policy_init();
    sys_message_file_init();
    pop_win_init();

    page_init("startup");
    root_ctl_page_init();
    root_page_add_all();
    root_page_add_all_device();
    //****************************************
    lv_font_bin_init();
    res_img_scan_all("./res/"); 

    root_page_enter_logo();

    root_ctl_init();

    return 0;
    //****************************************

	scene_info_t s_info;

	snprintf(s_info.homeid,   128,"%s","111");
	snprintf(s_info.sceneId,  128,"%s","111");
	snprintf(s_info.sceneName,128,"%s","111");
	snprintf(s_info.sceneIcon,128,"%s","1");

	scene_info_add(&s_info);

    snprintf(s_info.sceneName,128,"%s","2");
    snprintf(s_info.sceneIcon,128,"%s","2");
	scene_info_add(&s_info);

    snprintf(s_info.sceneName,128,"%s","3");
    snprintf(s_info.sceneIcon,128,"%s","3");
	scene_info_add(&s_info);

    snprintf(s_info.sceneName,128,"%s","4");
    snprintf(s_info.sceneIcon,128,"%s","4");
	scene_info_add(&s_info);

    snprintf(s_info.sceneName,128,"%s","5中国籍殴打事件发哦手机发到");
    snprintf(s_info.sceneIcon,128,"%s","5");
	scene_info_add(&s_info);

    snprintf(s_info.sceneName,128,"%s","6sdfasfdasdfzasfasfd");
    snprintf(s_info.sceneIcon,128,"%s","6");
	scene_info_add(&s_info);
    //****************************************

    ui_com_toast_create(3000,"访问失败");
    //****************************************

    system_message_add("耗材提醒","滤芯寿命不足");
    system_message_add("故障提醒","电热水过热");


    return 0;
}

int root_ctl_init(void)
{

    //****************************************
    root_ctl.time = lv_timer_create(root_ctl_time_callback,200,NULL);
    //****************************************************************
    log_i("root ctl create\n");
    //****************************************************************

    return 0;
}
